<!--结算支付明细-->
<template>
  <div>
    <f-search-form ref='search' :more='true' @searchHandler='searchHandler' @exportHandler='exportHandler' :show-export-btn='true' :exportUrl='api.hyOrderDetailsReturn.exportTemplate'>
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='业务员' name='saleManName' />
      <f-search-form-item label='单位名称' name='customName' />
      <f-search-form-item label='部门' name='deptId' type='select' :data='api.hyorder.listByCompanyId' :params='queryParam' value-key='deptId' label-key='deptName' slot='advanced' />
      <f-search-form-item label='发货日期' type='range' name='beginDate' slot='advanced' />
    </f-search-form>
    <f-table ref='table'
             rowKey='invoiceDetailsId'
             :showSetting='true'
             setting-key='settleTab1'
             :tableColumns='columns'
             :scroll='{x:true}'
             :showMultipleBtn='false'
             :showPagination='false'
             :showTotal='true'
             :multiple='false'
             handler='hySettlePayDetailsPageListHandler'
             :operator='operator'
             :autoLoad='false'
             @onSuccess='onSuccess'
             :params='queryParam'
             :api='api.bhid.list'>
      <span slot='drugType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text=="ZY"'>自营</a-tag>
           <a-tag color='#FF0000' v-if='text=="ZS"'>招商</a-tag>
       </span>
      <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
           <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
           <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
           <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
       </span>
    </f-table>
    <a-divider orientation='left'>开票明细</a-divider>
    <f-table ref='invoiceTable' rowKey='paymentId' :showSetting='false' setting-key='invoice_table' :tableColumns='invoiceColumns' :scroll='{x:true}' handler='hyInvoicePaymentPageListHandler' :showPagination='false' :showMultipleBtn='false' :multiple='false' :operator='operator2' :params='queryParam' :autoLoad='false' :api='api.payment'>
       <span slot='invoiceType' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==1'>普票</a-tag>
            <a-tag color='#108ee9' v-if='text==2'>专票</a-tag>
       </span>
      <span slot='paymentState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未支付</a-tag>
            <a-tag color='#108ee9' v-if='text==2'>已支付</a-tag>
       </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='invoiceDetails(record)'>明细</a>
            <a-divider type='vertical' />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
             <a-menu-item>
                <a href='javascript:;' @click='printOrder(record)'>资金支付单</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <print-modal ref='printModal'></print-modal>
    <invoice-details-drawer ref='invoiceDetailsDrawer'></invoice-details-drawer>
  </div>
</template>
<script>
import api from "../../../js/api"
import InvoiceDetailsDrawer from "@/views/module/haiying/order/settle/components/invoice_details_drawer"
import PrintModal from "@/views/module/haiying/print/print_modal"

export default {
  name: "PayDetails",
  components: { PrintModal, InvoiceDetailsDrawer },
  props: {
    columns: {
      type: Array,
      default: []
    },
    invoiceApply: {
      type: Number,
      default: null
    },
    invoiceData: {
      type: Object,
      default: null
    }
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    let operator2 = []
    operator2.push({
      name: "导出付款账户明细",
      that: this,
      handler: (table, that) => {
        that.http.exportExcel(that, {
          url: that.api.paymentDetails.exportUrl,
          data: {
            fileName: "付款通知单",
            settleApplyId: this.queryParam.paymentId,
            handlerName: "hyPaymentDetailsPageListHandler",
            columns: "[{name:'开票单位',key:'invoiceUnitName'},{name:'收款人',key:'payeeName'},{name:'开户行',key:'bankName'},{name:'收款账户',key:'bankNo'},{name:'付款分解金额',key:'settleAmount',needTotal:true,type:10},{name:'付款日期',key:'payDate'},{name:'备注',key:'remark'}]"
          }
        })
      }
    })
    return {
      api: Object.assign(api, this.api),
      multiple: false,
      deptId: "",
      //列表初始化查询参数
      queryParam: {
        fileName: "结算申请明细-",
        auth: 1,
        isFlp: 1
      },
      returnCustomBond: 0,
      selectIds: "",
      params1: {
        deptId: ""
      },
      invoiceColumns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "开票日期",
          align: "center",
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "开票单号",
          align: "center",
          width: "130px",
          dataIndex: "paymentNo"
        },
        {
          title: "发票类型",
          align: "center",
          width: "80px",
          dataIndex: "invoiceType",
          scopedSlots: { customRender: "invoiceType" }
        },
        {
          title: "收票单位",
          align: "left",
          width: "180px",
          ellipsis: true,
          dataIndex: "companyName"
        },
        {
          title: "开票单位",
          align: "left",
          ellipsis: true,
          width: "180px",
          dataIndex: "invoiceunitName"
        },
        {
          title: "发票项目",
          align: "left",
          ellipsis: true,
          width: "100px",
          dataIndex: "title"
        },
        {
          title: "结算金额",
          align: "left",
          width: "80px",
          type: 10,
          dataIndex: "amount"
        },
        {
          title: "开票金额",
          align: "left",
          width: "80px",
          type: 10,
          dataIndex: "invoiceAmount"
        },
        {
          title: "不含税金额",
          align: "left",
          width: "80px",
          type: 10,
          dataIndex: "noTaxAmount"
        },
        {
          title: "税费",
          align: "left",
          width: "80px",
          type: 10,
          dataIndex: "taxAmount"
        },
        {
          title: "3%开票金额",
          align: "left",
          width: "100px",
          dataIndex: "senondInvoiceAmount"
        },
        {
          title: "3%开票税金",
          align: "left",
          width: "100px",
          type: 10,
          dataIndex: "secondTaxAmount"
        },
        {
          title: "备注",
          align: "left",
          width: "80px",
          dataIndex: "remark"
        }, {
          title: "申请人",
          align: "left",
          ellipsis: true,
          width: "90px",
          dataIndex: "nickName"
        }, {
          title: "创建时间",
          align: "center",
          width: "90px",
          dataIndex: "createTime"
        }, {
          title: "支付状态",
          align: "center",
          width: "80px",
          fixed: "right",
          dataIndex: "paymentState",
          scopedSlots: { customRender: "paymentState" }
        }, {
          title: "操作",
          align: "center",
          dataIndex: "action",
          width: "150px",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      settleType: null,
      dataSource: [],
      operator: operator,
      operator2: operator2
    }
  },
  computed: {
    rowSelection() {
      return {
        getCheckboxProps: record => ({
          props: {
            disabled: record.settleInvoiceId || !record.orderDetailsId,
            name: record.orderDetailsId
          }
        })
      }
    }
  },
  methods: {
    setData(data) {
      if (data && data.paymentId) {
        this.queryParam.paymentId = data.paymentId
        this.queryParam.settleType = data.settleType
        this.queryParam.processInstanceId = data.processInstanceId
        this.$refs["table"].refresh(false)
      }
    },
    //部门切换
    deptChange(value) {
      this.queryParam.deptId = value
      //this.openMultiple()
      this.$refs.saleMan.initData(this.queryParam)
      this.$refs.table.refresh(true, this.queryParam)
      this.$forceUpdate()
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    onSuccess() {
      this.$refs["invoiceTable"].refresh(false)
    },
    printOrder(record) {
      this.$refs["printModal"].open(record.paymentId, 2, "Settle")
    },
    invoiceDetails(record){
      this.$refs.invoiceDetailsDrawer.showDrawer({
        ...record,
        processInstanceId:this.queryParam.processInstanceId
      })
    },
    /**
     * 刷新列表
     */
    onLoad() {
      this.$refs["table"].refresh(false)
      this.$refs["invoiceTable"].refresh(false)
      this.$emit("changeTab")
    }
  },
  created() {
  }
}
</script>